package com.ka.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.ka.lifemanagement.R;
import com.ka.model.GeneralModel;
import com.ka.model.MenuLeftModel;

public class MenuLeftAdapter extends ArrayAdapter<GeneralModel> {

	protected List<GeneralModel> listModel;
	protected int layout_id;
	protected Context ct;

	public MenuLeftAdapter(Context context, int resource,
			List<GeneralModel> objects) {
		super(context, resource, objects);
		layout_id = resource;
		listModel = objects;
		ct = context;
	}

	@Override
	public int getCount() {
		return listModel.size();
	}

	@Override
	public GeneralModel getItem(int position) {
		return listModel.get(position);
	}

	@Override
	public long getItemId(int position) {
		return listModel.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {
			LayoutInflater inflat = LayoutInflater.from(parent.getContext());
			convertView = inflat.inflate(layout_id, null);
			holder = new ViewHolder();
			holder.title = (TextView) convertView
					.findViewById(R.id.menu_left_title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		MenuLeftModel item = (MenuLeftModel) getItem(position);

		holder.title.setText(item.getTitle());
		holder.title.setCompoundDrawables(
				ct.getResources().getDrawable(R.drawable.ic_launcher), null,
				null, null);

		return convertView;
	}

	public static class ViewHolder {
		TextView title;
	}

}
